package com.jdk21.core.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public final class BigDecimalUtil {

    public static String generateShowMoney(BigDecimal money) {
        return money == null ? "" : money.stripTrailingZeros().toPlainString();
    }

    public static BigDecimal divide(Long va1, Long va2) {
        if (va1 == null || va2 == null) {
            return BigDecimal.ZERO;
        }
        return BigDecimal.valueOf(va1).divide(BigDecimal.valueOf(va2), 2, RoundingMode.HALF_UP);
    }

    public static BigDecimal divide(BigDecimal va1, Long va2, RoundingMode roundingMode) {
        if (va1 == null || va2 == null) {
            return BigDecimal.ZERO;
        }
        return va1.divide(BigDecimal.valueOf(va2), 2, roundingMode);
    }

    public static int roundHalfUpDivide(Long va1, Long va2) {
        if (va1 == null || va2 == null) {
            return 0;
        }
        return BigDecimal.valueOf(va1).divide(BigDecimal.valueOf(va2), 2, RoundingMode.HALF_UP).intValue();
    }
}
